#define _CRT_SECURE_NO_WARNINGS
#include "Huffman.h"
#include "Stack.h"
int main()
{
	char str[10][MAXLENGH];
	int n = Input(str);
	int i;
	for (i = 0; i < n; i++)
	{
		if (str[i][0] == '0')
			break;
		int frequncy[26] = { 0 };
		int n = HTFrequncy(str[i], frequncy);
		HuffmanTree tree = HTCreate(n, frequncy);
		PrintFrequncy(frequncy);
		PrintFinalState(tree, 2 * n);
		char coded[1000] = { 0 };
		char list[26][26] = { 0 };
		HTEncoding(str[i], coded, list, tree, frequncy, n);
		PrintCodingList(list);
		printf("%s\n", coded);
		HTDeCoding(tree, coded, frequncy, n);
		free(tree);
	}
	return 0;
}